package com.app114.app.android.rk;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;

public class ListFragment extends Fragment implements OnItemClickListener {

	private GridView gridView;

	static String[] Category = { "应用", "小说", "购物", "微博", "游戏", "笑话", "生活", "交友","其他" };

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		gridView = (GridView) inflater.inflate(R.layout.layout_gridview, container, false);
		gridView.setOnItemClickListener(this);
		return gridView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		gridView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, Category));
	}

	public static ListFragment newListFragment(int id) {
		final ListFragment fragment = new ListFragment();
		return fragment;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		Intent intent = new Intent(getActivity(), CategoryActivity.class);
		intent.setAction(Category[position]);
		startActivity(intent);
	}

}
